package com.zhongyouyun.wx.wxapplet.cqyc.controller;

import cn.hutool.core.util.ObjectUtil;
import com.zhongyouyun.cqyc.model.BusinessHallModel;
import com.zhongyouyun.cqyc.model.PocketBookModel;
import com.zhongyouyun.cqyc.service.PocketBookService;
import com.zhongyouyun.cqyc.service.PocketBookTypeService;
import com.zhongyouyun.other.model.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("wx/wxapplet/cqyc/pocketBook")
@Api(value = "烟草城区-微信小程序口袋书操作", tags = {"烟草城区-微信小程序口袋书操作"})
public class WxAppletPocketBookController {

    @Autowired
    private PocketBookTypeService pocketBookTypeService;
    @Autowired
    private PocketBookService pocketBookService;

    @GetMapping("/getDetails")
    @ResponseBody
    @ApiOperation(value = "获取口袋书信息", notes = "获取口袋书信息")
    public Result getDetails(@ApiParam(name = "口袋书ID", value = "id", required = true) @RequestParam(value = "id") String id) {
        PocketBookModel bookServiceById = pocketBookService.getById(id);
        if (ObjectUtil.isNotEmpty(bookServiceById)) {
            return Result.builder().message("成功").status(0).data(bookServiceById).build();
        } else {
            return Result.builder().message("获取失败").success(false).status(1).build();
        }
    }

    @GetMapping("/getPocketBook")
    @ResponseBody
    @ApiOperation(value = "根据关键字获取口袋书列表", notes = "根据关键字获取口袋书列表")
    public Result getPocketBook(@ApiParam(name = "口袋书搜索条件", value = "search", required = true) @RequestParam(value = "search") String search) {
        List<Map> pocketBookList = pocketBookService.getPocketBookList(search);
        if (ObjectUtil.isNotEmpty(pocketBookList)) {
            return Result.builder().message("成功").status(0).data(pocketBookList).build();
        } else {
            return Result.builder().message("你可以说的更具体一些！").status(0).build();
        }
    }

}
